home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AOL File Library: 2,801 to 2,900
/
aol-file-protocol-4400-2801-to-2900.zip
/
AOLDLs
/
C++ Files Library
/
Acere (PowerPlant, Game) 1.2
/
AcereÄ.sit
/
Acereƒ
/
Code
/
CardDeck.cp
< prev
next >
Wrap
Text File
|
1995-03-05
|
24KB
|
843 lines
#include "CardDeck.h"
#include "CTextDoc.h"
#include "AcereApp.h"
#include "CardWindow.h"
#define kNoCard -1
static RGBColor RGBwhite;
static RGBColor RGBdkGrey;
extern unsigned long ourAvailRam;
extern Boolean hasSmallScreen;
extern CTextDoc *theDoc;
extern CardWindow *gMainWindow;
CardDeck *theDeck;
RGBColor myBlack, myWhite;
CardDeck::CardDeck()
{
short i;
theDeck = this;
GetDateTime((unsigned long *)&qd.randSeed); // initialize randomizer when we create a new deck object
// since Generate doesn't do this, we only do it once per session
RGBwhite.red = RGBwhite.blue = RGBwhite.green = 0xffff;
RGBdkGrey.red = RGBdkGrey.blue = RGBdkGrey.green = 0x3fff;
myBlack.red = myBlack.green = myBlack.blue = 0;
myWhite.red = myWhite.green = myWhite.blue = 0xFFFF;
for (i=0; i< 4; i++)
{
suitCIcons[i] = GetCIcon(2000+i);
}
columnOffsets[0] = 6;
columnOffsets[1] = 24;
columnOffsets[2] = 42;
GetGWorld(&mSavePort, &mSaveDevice);
gwRect.top = gwRect.left = 0;
gwRect.right = GetCardWidth() * (NumCardsPerSuit + 1);
gwRect.bottom = GetCardHeight() * NumSuits;
QDErr err = ::NewGWorld(&cardGWorld, 4, &gwRect, 0L, nil, 0L);
ThrowIfOSErr_(err);
ThrowIfNil_(cardGWorld);
// Make offscreen GWorld the current one and prepare it
// for drawing by setting the coordinate system, and locking
// and erasing the pixels.
::SetGWorld(cardGWorld, nil);
// ::SetOrigin(gwRect.left, gwRect.top);
::LockPixels(::GetGWorldPixMap(cardGWorld));
/* set the foreground color to black */
RGBForeColor( &myBlack );
RGBBackColor( &myWhite );
::EraseRect(&gwRect);
GetShortCardMask();
offScreen = ::GetGWorldPixMap( cardGWorld );
::SetGWorld(mSavePort, mSaveDevice);
ZapOldDeck();
GenerateNewDeck(true);
nextCardPosition = 0;
}
CardDeck::~CardDeck()
{
short i;
for (i=0; i< 4; i++)
{
DisposCIcon(suitCIcons[i]);
}
DisposeGWorld(cardGWorld);
}
void CardDeck::GenerateNewDeck(Boolean doOffScreenDraw)
{
#define abs(x) (x) < 0 ? (-x) : (x)
unsigned short i = 0, tempShort;
Boolean happy;
CardStruct theCardInfo;
Rect theRectToDraw;
for (i = 0; i < NumCards; i++)
theCardPositions[i] = -1;
for (i = 0; i < NumCards; i++)
{
happy = false;
do
{
tempShort = abs(Random());
tempShort = tempShort% NumCards;
if ((theCardPositions[tempShort] == -1) && (theCards[i] == -1)) // card is unassigned & so is position
{
happy = true;
theCardPositions[tempShort] = i;
theCards[i] = tempShort;
}
} while (!happy);
if (doOffScreenDraw)
{
GetCardInfo(theCards[i], &theCardInfo);
CalcOffScreenRect(&theCardInfo, &theRectToDraw);
DrawCardOffScreen(&theCardInfo, theRectToDraw, false);
}
}
}
void CardDeck::ZapOldDeck() // after we finish a game to cleanup before generating a new one
{
short i;
for (i=0; i < NumCards; i++)
{
theCards[i] = -1;
}
}
void CardDeck::DrawCardOffScreen(CardStruct *whichCard, Rect theRect, Boolean highlight)
{
Rect tempRect, theDrawRect = theRect;
RGBColor theBackColor;
// CIconHandle theIcon;
short saveFont, saveSize;
Str15 cardString;
::SetGWorld(cardGWorld, nil);
// ::SetOrigin(gwRect.left, gwRect.top);
::LockPixels(::GetGWorldPixMap(cardGWorld));
::EraseRect(&theRect);
Boolean fullCard = (theRect.bottom - theRect.top > 30);
if (whichCard == nil)
return;
if (whichCard->card == kNoCard)
return;
// GetCardInfo(whichCard, theCard);
GetBackColor(&theBackColor);
if ((highlight) && fullCard)
RGBBackColor(&RGBdkGrey);
else
RGBBackColor(&RGBwhite);
if (fullCard)
{
FillRoundRect(&theRect, 20, 20, &qd.white);
// EraseRoundRect(&theRect, 20, 20); // otherwise puts the pattern in.
FrameRoundRect(&theRect, 20, 20);
}
else // we need to do PART of a rounded rectangle
{
// DrawShortCardBoundary(theRect);
}
tempRect.top = theRect.top + 2;
tempRect.left = theRect.left + 4;
SizeRect(&tempRect, 12, 16);
// theIcon = theApp->suitPats[whichCard->suit][0];
PlotCIcon(&tempRect,theApp->suitPats[whichCard->suit][0]);
saveFont = qd.thePort->txFont;
saveSize = qd.thePort->txSize;
cardString[0] = 1;
switch(whichCard->card)
{
case 1:
cardString[1] = 'A';
break;
case 11:
cardString[1] = 'J';
break;
case 12:
cardString[1] = 'Q';
break;
case 13:
cardString[1] = 'K';
break;
default:
NumToString((long)whichCard->card, cardString);
}
TextSize(12);
TextFont(systemFont);
tempRect.left += 14;
MoveTo(tempRect.left, tempRect.bottom -4);
DrawString(cardString);
// theDrawRect.top += 20;
if (fullCard)
{
if (cardString[1] == 'A')
{
tempRect.left = theDrawRect.left + ((theDrawRect.right - theDrawRect.left)/2) - 12;
tempRect.top = theDrawRect.top + ((theDrawRect.bottom - theDrawRect.top)/2) - 16;
SizeRect(&tempRect, 24, 32);
PlotCIcon(&tempRect, suitCIcons[whichCard->suit]);
tempRect.top = theRect.bottom - 19;
tempRect.left = theRect.right - 15;
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect,theApp->suitPats[whichCard->suit][1]);
}
else if (cardString[1] == '2')
{
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
}
else if (cardString[1] == '3')
{
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[1];
tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
}
else if (cardString[1] == '4')
{
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
}
else if (cardString[1] == '5')
{
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[1];
tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
}
else if (cardString[1] == '6')
{
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
}
else if (cardString[1] == '7')
{
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[1];
tempRect.top = theDrawRect.top + GetRowOffset(2, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(3, 3);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
}
else if (cardString[1] == '8')
{
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(1, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(2, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(2, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(3, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(4, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(4, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
}
else if (cardString[1] == '9')
{
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(1, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(2, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(2, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(3, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(4, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(4, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[1];
tempRect.top = theDrawRect.top + GetRowOffset(2, 4) + (GetRowOffset(3, 4) - GetRowOffset(2, 4))/2;
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
}
else if (cardString[1] == '1')
{
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(1, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(1, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(2, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(2, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(3, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(3, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[0];
tempRect.top = theDrawRect.top + GetRowOffset(4, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[2];
tempRect.top = theDrawRect.top + GetRowOffset(4, 4);
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
tempRect.left = theDrawRect.left + columnOffsets[1];
tempRect.top = theDrawRect.top + GetRowOffset(1, 4) + (GetRowOffset(2, 4) - GetRowOffset(1, 4))/2;
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][0]);
tempRect.left = theDrawRect.left + columnOffsets[1];
tempRect.top = theDrawRect.top + GetRowOffset(3, 4) + (GetRowOffset(4, 4) - GetRowOffset(3, 4))/2;
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect, theApp->suitPats[whichCard->suit][1]);
}
else
{
PicHandle ourPicture;
ourPicture = GetPicture(257+ (3*whichCard->suit) + (whichCard->card - 11));
tempRect.left = theRect.left + ((theRect.right - theRect.left)/2) - 17;
tempRect.top = theRect.top + ((theRect.bottom - theRect.top)/2) - 30;
SizeRect(&tempRect, 34, 69);
DrawPicture(ourPicture, &tempRect);
ReleaseResource((Handle)ourPicture);
tempRect.top = theRect.bottom - 19;
tempRect.left = theRect.right - 15;
SizeRect(&tempRect, 12, 16);
PlotCIcon(&tempRect,theApp->suitPats[whichCard->suit][1]);
}
}
// restore everything
TextSize(saveSize);
TextFont(saveFont);
// RGBBackColor(&theBackColor);
::UnlockPixels(::GetGWorldPixMap(cardGWorld));
::SetGWorld(mSavePort, mSaveDevice);
}
void CardDeck::DrawCard(PlayingCard *whichCard, Rect theRect, Boolean highlight)
{
Rect offscreenRect, adjustedRect = theRect;
GrafPtr myPort = gMainWindow->GetMacPort();
CalcOffScreenRect(whichCard, &offscreenRect);
if (theRect.bottom > (theRect.top + 30))
{
OffsetRgn(fullCardMask, theRect.left - (*fullCardMask)->rgnBBox.left,
theRect.top - (*fullCardMask)->rgnBBox.top);
CopyBits((BitMap *)*offScreen, &myPort->portBits, &offscreenRect, &theRect, srcCopy, fullCardMask);
FrameRgn(fullCardMask);
}
else
{
adjustedRect.bottom = adjustedRect.top + GetCardHeight();
OffsetRgn(shortCardMask, theRect.left - (*shortCardMask)->rgnBBox.left,
theRect.top - (*shortCardMask)->rgnBBox.top);
CopyBits((BitMap *)*offScreen, &myPort->portBits, &offscreenRect, &adjustedRect, srcCopy, shortCardMask);
FrameRgn(shortCardMask);
}
}
short CardDeck::GetNextCardPosition(void)
{
nextCardPosition++;
if (nextCardPosition >= NumCards)
return (kNoCard);
return ((short)nextCardPosition);
}
short CardDeck::GetPositionValue(short whichPosition)
{
return ((short)theCardPositions[whichPosition]);
}
void CardDeck::GetCardInfo(short whichCard, CardStruct *cardInfo)
{
if ((whichCard == kNoCard) || (whichCard < 0) || (whichCard > NumCards))
{
cardInfo->card = kNoCard;
return;
}
cardInfo->suit = whichCard / 13;
cardInfo->card = (whichCard % 13) + 1;
if ((cardInfo->suit == 0) || (cardInfo->suit == 3))
cardInfo->color = blackCard;
else
cardInfo->color = redCard;
}
void CardDeck::GetCardInfo(short whichCard, PlayingCard *cardInfo)
{
if ((whichCard == kNoCard) || (whichCard < 0) || (whichCard > NumCards))
{
cardInfo->card = kNoCard;
return;
}
cardInfo->suit = whichCard / 13;
cardInfo->card = (whichCard % 13) + 1;
if ((cardInfo->suit == 0) || (cardInfo->suit == 3))
cardInfo->color = blackCard;
else
cardInfo->color = redCard;
}
//void CardDeck::DrawShortCardBoundary(Rect theRect)
void CardDeck::GetShortCardMask(void)
{
Rect tempRect /* = theRect */;
RgnHandle /*newRgn, */oldRgn;
tempRect.left = tempRect.top = 0;
tempRect.right = tempRect.left + GetCardWidth();
tempRect.bottom = tempRect.top + GetCardHeight();
fullCardMask = NewRgn();
OpenRgn();
FrameRoundRect(&tempRect, 20, 20);
FillRgn(fullCardMask, &qd.black);
CloseRgn(fullCardMask);
oldRgn = NewRgn();
OpenRgn();
tempRect.bottom +=20;
FrameRoundRect(&tempRect, 20, 20);
CloseRgn(oldRgn);
shortCardMask = NewRgn();
OpenRgn();
tempRect.bottom += 22;
tempRect.top += 22;
FrameRoundRect(&tempRect, 20, 20);
CloseRgn(shortCardMask);
DiffRgn(oldRgn, shortCardMask, shortCardMask);
FillRgn(shortCardMask, &qd.black);
FrameRgn(shortCardMask);
// DisposeRgn(newRgn);
DisposeRgn(oldRgn);
}
void CardDeck::CalcOffScreenRect(PlayingCard *whichCard, Rect *theRect)
{
// note that the suit is the row and the card is the column. Clever, huh?
theRect->top = GetCardHeight() * whichCard->suit;
theRect->bottom = theRect->top + GetCardHeight();
theRect->left = GetCardWidth() * whichCard->card;
theRect->right = theRect->left + GetCardWidth();
}
void CardDeck::CalcOffScreenRect(CardStruct *whichCard, Rect *theRect)
{
// note that the suit is the row and the card is the column. Clever, huh?
theRect->top = GetCardHeight() * whichCard->suit;
theRect->bottom = theRect->top + GetCardHeight();
theRect->left = GetCardWidth() * whichCard->card;
theRect->right = theRect->left + GetCardWidth();
}
short CardDeck::GetCardWidth(void)
{
if (hasSmallScreen)
return (50);
else
return (60);
}
short CardDeck::GetCardHeight(void)
{
if (hasSmallScreen)
return (75);
else
return (90);
}
PlayingCard::PlayingCard(CardStruct *theStruct) : LPane()
{
suit = theStruct->suit;
card = theStruct->card;
color = theStruct->color;
itsOwner = theStruct->itsOwner;
// LPane::LPane();
mFrameSize.width = theDeck->GetCardWidth();
mFrameSize.height = theDeck->GetCardHeight();
// mSuperView = itsSuperView;
// itsCardInfo = *theStruct;
}
PlayingCard::~PlayingCard()
{
}
void PlayingCard::FillDataStruct(CardStruct *theStruct)
{
suit = theStruct->suit;
card = theStruct->card;
color = theStruct->color;
itsOwner = theStruct->itsOwner;
// itsCardInfo = *theStruct;
}
void SizeRect(Rect *theRect, short width, short height)
{
theRect->right = theRect->left + width;
theRect->bottom = theRect->top + height;
}
short GetRowOffset(short whichRow, short numRows)
{
short returnVal = 0;
if (hasSmallScreen)
{
switch (numRows)
{
case 3:
switch(whichRow)
{
case 1:
returnVal = 21;
break;
case 2:
returnVal = 36;
break;
case 3:
returnVal = 51;
break;
}
break;
case 4:
switch(whichRow)
{
case 1:
returnVal = 10;
break;
case 2:
returnVal = 26;
break;
case 3:
returnVal = 42;
break;
case 4:
returnVal = 58;
break;
}
break;
}
}
else
{
switch (numRows)
{
case 3:
switch(whichRow)
{
case 1:
returnVal = 21;
break;
case 2:
returnVal = 42;
break;
case 3:
returnVal = 63;
break;
}
break;
case 4:
switch(whichRow)
{
case 1:
returnVal = 17;
break;
case 2:
returnVal = 35;
break;
case 3:
returnVal = 53;
break;
case 4:
returnVal = 74;
break;
}
break;
}
}
return (returnVal);
}